package com.cetcs.kmga.dataManager.entity.logManager.vi;

import com.cetcs.kmga.dataManager.global.ResLogType;
import com.cetcs.kmga.dataManager.util.MD5;
import org.apache.commons.lang.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 日志搜索基础类
 *
 * @author xutao
 * @version V1.0 创建时间：2017-09-21 13:28
 * Copyright 2017 by CETC
 */
public class LogSearchBasicVi {

    private int page = 1;
    private int pageSize = 5;
    private String pageType;

    private String clientIp;

    private boolean isNotExport = true;

    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    /**
     * 1：高级查询
     * 0：普通查询
     */
    private Integer queryType;
    /**
     * 显示数组
     */
    private List<Integer> showNum;

    /**
     * 初始化显示 0：是；1：不是
     */
    private Integer firstShow;

    /**
     * 时间间隔查询与模糊匹配查询
     */
    private LogSearchTopVi top1;

    /**
     * 第二值
     */
    private List<LogSearchProbeVi> top2;

    /**
     * 第三个值
     */
    private LogSearchOtherVi top3;

    public List<Integer> getShowNum() {
        return showNum;
    }

    public void setShowNum(List<Integer> showNum) {
        this.showNum = showNum;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getPageType() {
        return pageType;
    }

    public void setPageType(String pageType) {
        this.pageType = pageType;
    }

    public LogSearchTopVi getTop1() {
        return top1;
    }

    public void setTop1(LogSearchTopVi top1) {
        this.top1 = top1;
    }

    public List<LogSearchProbeVi> getTop2() {
        return top2;
    }

    public void setTop2(List<LogSearchProbeVi> top2) {
        this.top2 = top2;
    }

    public LogSearchOtherVi getTop3() {
        return top3;
    }

    public void setTop3(LogSearchOtherVi top3) {
        this.top3 = top3;
    }

    public Integer getFirstShow() {
        return firstShow;
    }

    public void setFirstShow(Integer firstShow) {
        this.firstShow = firstShow;
    }

    public Integer getQueryType() {
        return queryType;
    }

    public void setQueryType(Integer queryType) {
        this.queryType = queryType;
    }

    public boolean isNotExport() {
        return isNotExport;
    }

    public void setNotExport(boolean notExport) {
        isNotExport = notExport;
    }

    @Override
    public String toString() {
        MD5 md5 = new MD5();
        if (this.pageType.equals(ResLogType.HbaseFWRZ.toString()) ||
                this.pageType.equals(ResLogType.MySQLFWRZ.toString()) || this.pageType.equals(ResLogType.MongoDBFWRZ.toString())
                || this.pageType.equals(ResLogType.FTPCJRZ.toString()) || this.pageType.equals(ResLogType.SolrFWRZ.toString())) {
            String top2KeyStr = "";
            if (this.top2 != null) {
                List<String> top2KeyList = this.top2.stream().filter(p -> p.getVal() != null && p.getVal().length > 0).map(p -> String.join(",", p.getVal())).collect(Collectors.toList());
                if (top2KeyList != null && top2KeyList.size() > 0) {
                    top2KeyStr = String.join(",", top2KeyList);
                }
            }
            String top3KeyStr = "";
            if (this.top3 != null && this.top3.getResult() != null) {
                List<List<String>> top3Res = this.top3.getResult();
                List<String> top3KeyList = top3Res.stream().filter(p -> StringUtils.isNotBlank(p.get(1))).map(p -> p.get(1)).collect(Collectors.toList());
                if (top3KeyList != null && top3KeyList.size() > 0) {
                    top3KeyStr = String.join(",", top3KeyList);
                }
            }
            String str = this.pageType + this.top1.toString() + top2KeyStr + top3KeyStr + this.getClientIp() + this.isNotExport();
            String md5Str = md5.getMD5ofStr(str);
            return md5Str;
        } else {
            if (this.queryType != null && this.queryType.intValue() == 1) {
                String dateRangeStr = this.top1.getDateRange();
                if (!StringUtils.isNotBlank(dateRangeStr)) {
                    dateRangeStr = "1";
                }
                String md5Str = md5.getMD5ofStr(dateRangeStr);
                return md5Str;
            } else {
                String str = this.pageType + this.top1.toString() + this.getClientIp() + this.isNotExport();
                String md5Str = md5.getMD5ofStr(str);
                return md5Str;
            }
        }
    }

}
